package com.loyal.loyalerp.basedata.permission.util;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.loyal.loyalerp.basedata.permission.mapper.GyPermissionMapper;
import com.loyal.loyalerp.basedata.permission.model.GyPermission;

@Component
public class PermissionCodeJsonSerializer extends JsonSerializer<String>{
	
	@Autowired
	GyPermissionMapper gyPermissionMapper;
	

	@Override
	public void serialize(String str, JsonGenerator gen, SerializerProvider serializers)
			throws IOException, JsonProcessingException {
		/*
		 * 集合不能实现，一次只能写一个
		List<GyPermission> permissionList=gyPermissionMapper.listPermission();
		for(GyPermission permission : permissionList) {
			String entityCode=permission.getEntitycode();
			String actionCode=permission.getActioncode();
			str=entityCode+"_"+actionCode;
			gen.writeString(str);
		}
		*/
		GyPermission permission=gyPermissionMapper.selectECAndACByPermissionCode(str);
		String entityCode=permission.getEntitycode();
		String actionCode=permission.getActioncode();
		String str2=entityCode+"_"+actionCode;
		gen.writeString(str2);
		
	
	}
	
	
}
